package org.huamoxi.config;

import org.huamoxi.constant.TokenConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * 令牌相关配置
 */
@Configuration
public class JwtTokenConfig {
    /**
     * 设置令牌存储方式
     */
    @Bean("jwtTokenStore")
    TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Bean("jwtAccessTokenConverter")
    JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(TokenConstants.SECRET);
        return converter;
    }
}
